"""用于测试opencv检测图片的轮廓功能"""
import cv2
import numpy as np

#加载图片
img=cv2.imread('combo.png')

#查看像素值
print(img[0,0],img[479,639])#三通道图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# 二值化处理
Ret, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)#类型处理方法
print(type(Ret),Ret)
#轮廓检测
contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

# 去除外层黑边
contours = contours[1:]        # 扔掉 0 号
hierarchy  = hierarchy[:, 1:, :]
print(contours,hierarchy)

output = np.zeros_like(img)
#绘制轮廓
cv2.drawContours(img, contours, -1, (0, 0, 255), 2)#绘制所有的轮廓
cv2.imshow('img',img)
cv2.waitKey(0)


